<?php
	defined('RUN') or die('No access');

	class PostController
	{
		public function index($page=1)
		{
			$data = Model::get('website')->getLayoutData();
			
			$data['posts'] = Model::get('post')->getByPage('`id`,`name`,`images`,`content_short`',$page,9);
			
			// Pagination
			$total_news = Model::get('post')->getTotalRows();
			Pagination::set('post', $total_news, 9, 3, $page);
			$data['pagination'] = Pagination::get('post');
			
			$data['title'] = 'Bài giảng';
			$data['content_file'] = 'post/index.tpl';
			View::load('layout.tpl', $data, $data['temp']);
		}
		public function read($id)
		{
			$data = Model::get('website')->getLayoutData();
			
			$data['posts'] = Model::get('post')->getById($id,'`id`,`name`,`content_short`,`content`,`description`,`keywords`,`category_id`');
			$data['related'] =  Model::get('post')->getRelated('`id`,`name`', $data['posts']['category_id'],$data['posts']['id']);	
			
			$data['title'] = ($data['posts'] ? $data['posts']['name'] : Config::get('page_name'));
			$data['description'] = ($data['posts'] ? $data['posts']['description'] : Config::get('page_description'));
			$data['keywords'] = ($data['posts'] ? $data['posts']['keywords'] : Config::get('page_keywords'));
			$data['content_file'] = 'post/read.tpl';
			View::load('layout.tpl', $data, $data['temp']);
		}
	}
